package picasa;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageFilter;
import java.awt.image.FilteredImageSource;

public class Conversion {
	
//	Convert the image into a BufferedImage_Type.ARGB
	public static BufferedImage convertToBufferedImage(Image img, int wid, int ht, int type){
		
		BufferedImage bi = new BufferedImage(wid,ht,type);
		Graphics2D g2d = bi.createGraphics();
		g2d.drawImage(img,0,0,wid,ht,null);
		g2d.dispose();
		return bi;
		
	}
	 public static BufferedImage convert(BufferedImage source, int targetType) {
	      int sourceType = source.getType();
	     
	      if (sourceType == targetType)
	          return source;
	      BufferedImage result = new BufferedImage(source.getWidth(), source.getHeight(), targetType);
	      Graphics2D g = result.createGraphics();
	      g.drawRenderedImage(source, null);
	      g.dispose();
	      return result;
	  }
	 public static Image convertToImage(BufferedImage bufImage){
		 AffineTransformOp aop = new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_BILINEAR);
		 BufferedImageFilter bif = new BufferedImageFilter(aop);
		 FilteredImageSource fsource = new FilteredImageSource(bufImage.getSource(), bif);
		 Image img = Toolkit.getDefaultToolkit().createImage(fsource);
		 return img;
	 }

}
